<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/fmt.tld" prefix="fmt" %>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %> 
<%String path = request.getContextPath() ;%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>巡检结果详情页面</title>
	<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
	<div class="Wrapper">
		<div>
			<form id="routeMain">
				<div class="fieldset1 tabel_col clearFix">
					<!-- 巡检结果 -->
					<div class="caption">
						<span class="title">巡检结果</span>
					</div>
					<div class="fieldBox col_50">
						<div class="label">巡检批次</div>
						<div class="field">
							<span id="routeNo" name="routeNo">&nbsp;</span>
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">事业部</div>
						<div class="field">
							<span id="bussDepartmentNm" name="bussDepartmentNm">&nbsp;</span>
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">省公司</div>
						<div class="field">
							<span id="proCompanyNm" name="proCompanyNm">&nbsp;</span>
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">巡检状态</div>
						<div class="field">
							<span id="routeStateNm" name="routeStateNm">&nbsp;</span>
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">巡检开始时间</div>
						<div class="field">
							<span id="routeBeginDate" name="routeBeginDate">&nbsp;<fmt:formatDate type="date"  value="${routeMainVo.routeBeginDate}"/></span>
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">巡检结束时间</div>
						<div class="field">
							<span id="routeEndDate" name="routeEndDate">&nbsp;<fmt:formatDate type="date"  value="${routeMainVo.routeEndDate}"/></span>
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">巡检人员</div>
						<div class="field">
							<span id="inspectors" name="inspectors">&nbsp;</span>
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">本次巡检数量</div>
						<div class="field">
							<c:if test="${btnFlag == 'yes' }">
								<input name="routeNum" id="routeNum" type="text" class="ui-textbox" value="" validate="{required:true,digits:true}">
								<span class="requiredSymbol">*</span>
							</c:if>
							<c:if test="${btnFlag == 'no' }">
								<span id="routeNum_1" name="routeNum_1">&nbsp;</span>
							</c:if>
						</div>
					</div>
					<!-- 隐藏事业部、省公司参数 -->
	                <div class="fieldBox col_100" style="display:none;">
						<div class="field">
							<input name="mainId" id="mainId" type="text" class="ui-textbox" value="${id}">
	                        <input name="bussDepartment" id="bussDepartment" type="text" class="ui-textbox" value="${routeMainVo.bussDepartment}">
	                        <input name="proCompany" id="proCompany" type="text" class="ui-textbox" value="${routeMainVo.proCompany}">
	                        <input name="routeState" id="routeState" type="text" class="ui-textbox" value="${routeMainVo.routeState}">
	                    </div>
	                </div>
				</div>
				
				<!-- 表单按钮 -->
				<c:if test="${btnFlag == 'yes' }">
					<div class="btnsBox">
						<span id="refreshBtn" class="sq-button sq-button-round" onclick="refreshList()">刷新</span>
		            </div>
	            </c:if>
			</form>
			
			<div class="fieldset1 tabel_col clearFix">
				<!-- 巡检详情列表显示块 -->
				<div class="caption">
					<span class="title">巡检详情</span>
					<span  class="sq-button sq-button-round" onclick="importRouteDetail()">导出巡检结果</span>
				</div>
				<div class="fieldBox col_100">
					<div class="sqPanel">
						<div id="detailGrid">
							<div id="ligergrid_detail" class="sq-grid"></div>
							<div id="ligergrid_detail2" class="sq-grid Hide"></div>
						</div>
					</div>
				</div>
				<!-- 保存按钮 -->
				<div id="saveShow"></div>
				<c:if test="${btnFlag == 'yes' }">
				   <c:if test="${routeMainVo.routeNum>0}">
						<div style="text-align: center;line-height: 3em;">
							<span id="saveBtn" class="sq-button sq-button-round" onclick="saveRouteList()">保存</span>
			            </div>
			        </c:if>
			        <div id="saveBtndiv2" style="text-align: center;line-height: 3em;" class="Hide">
						<span id="saveBtn2" class="sq-button sq-button-round" onclick="saveRouteList()">保存</span>
			        </div>
	            </c:if>
			</div>
		</div>
	</div>
	
	<script type="text/javascript">
		var grid = null;
	    
		//加载
		$(function () {
			initForm();//初始化表单
		    initGrid();//初始化列表
		    setData();//初始化巡检主表数据
		});
		
		//初始化表单
		function initForm(){
			$("#routeMain").ligerForm({
				validate: true
			});
		}
		
		//查询参数
		function getSearchParams(){
			var form = new liger.get("routeMain");
			var data = form.getData();
			return data;
		}
		
		//设置页面数据
	    function setData(){
	    	//加载表单
	    	var form = liger.get("routeMain");
			form.setData({
				routeNum: "${routeMainVo.routeNum}"
	    	});
			$("#routeNum_1").html("${routeMainVo.routeNum}");
			$("#routeNo").html("${routeMainVo.routeNo}");
			$("#bussDepartmentNm").html("${routeMainVo.bussDepartmentNm}");
			$("#proCompanyNm").html("${routeMainVo.proCompanyNm}");
 	    	$("#inspectors").html("${routeMainVo.inspectors}");
 	    	//巡检状态
 	    	if("${routeMainVo.routeState}" == "0"){
 	    		$("#routeStateNm").html("未巡检");
 	    	}else if("${routeMainVo.routeState}" == "1"){
 	    		$("#routeStateNm").html("巡检中");
 	    	}else if("${routeMainVo.routeState}" == "2"){
 	    		$("#routeStateNm").html("巡检结束");
 	    	}
 	    	
	    }
		
		//格式化时间1：YYYY-MM-DD
		function renderDate(dateStr1){
			var dateStr2 = "";
			if(null != dateStr1){
				var date = new Date(dateStr1);
				dateStr2 = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
			}
			return dateStr2;
		}
		
		//初始化列表
		function initGrid(){
			var mainId = $("#mainId").val();
			$("#ligergrid_detail").ligerGrid({
				url:'<%=path%>/archive/arcRouteDetail/initList.do',
				method:'get',
				parms:{mainId: mainId},
				columns:[
					{ display: '承租人姓名', name: 'cstNm', width: 200, align:'center', enabledSort:true},
					{ display: '支付表号', name: 'paylistCode', width: 160, align:'center', enabledSort:true},
					{ display: '省公司档案袋编号', name: 'portfolioNumberProvince', width: 130, align:'center', enabledSort:true},
					{ display: '总部档案袋编号', name: 'portfolioNumber', width: 130, align:'center', enabledSort:true},
					{ display: '归档状态', name: 'storageStatusNm', width: 90, align:'center', enabledSort:true},
					{ display: '巡检状态', name: 'routeState', width: 90, align:'center', enabledSort:true,
						render: function (rowdata, rowindex, value, column) { 
							var h = '';
							if(rowdata.routeState == '0'){
								h = '未巡检';
							}else if(rowdata.routeState == '1'){
								h = '巡检中';
							}else if(rowdata.routeState == '2'){
								h = '巡检结束';
							}
							return h;
						}},
					{ display: '巡检结果', name: 'routeResult', width: 90, align:'center', enabledSort:true,
						render: function (rowdata, rowindex, value, column) { 
							var h = '';
							if(rowdata.routeResult == '0'){
								h = '缺失';
							}else if(rowdata.routeResult == '1'){
								h = '齐全';
							}
							return h;
						}},
					{ display:'操作', isSort:false, width: 150, align:'center', 
						render:function (rowdata, rowindex, value){
							var h="";
				            	h+='<a class="sq-button-hasicon" href="javascript:detailPayInfo(';
				                h+="'"+rowdata.id+"'";
				                h+=")\">查看</a>";
				                //更新结果
								if("${operation }" == "update" && rowdata.routeState != "2"){
					                h+='<a class="sq-button-hasicon" href="javascript:updatePayResult(';
					                h+="'"+rowdata.id+"'";
					                h+=")\">更新结果</a>";
								}else{
				                	h+='<font class="sq-button-hasicon" color="c9c9c9">更新结果</font>';
				                }
							return h;
						}
					}
				],
				pageSize:10,
				usePager: true,//是否有分页便签
				root:'rows',
				record:'total',
				hideLoadButton:false,
				width:'100%',
				heightDiff:-2,
				checkbox:false,//列表是否有选择框
				rownumbers:true//列表是否有行号
			});
			grid = liger.get("ligergrid_detail");
		}
		
		//刷新
		function refreshList(){
			var routeNum = $("#routeNum").val();
			var ligerForm = liger.get("routeMain");
			if (!ligerForm.valid()) {
				top.$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO,SQ_type: "warning"});
				return false; //验证不通过，不执行以下代码
			}
			$.ligerDialog.confirm('确定刷新巡检详情列表吗?', function (flag) {
				if(flag == false)return;
				//获取表单数据
				var data = ligerForm.getData();
				var wait_dialog = null;
				var url = '<%=path%>/archive/arcRouteDetail/refreshRouteList.do';
				$.ajax({
					type: 'get',
					dataType: 'json',
					data: data,
					url: url,
					beforeSend: function(){
						wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
					},
					success:function(result){
						wait_dialog.close();
						if(null != result.data && result.success == 1){
							initGridData(result.data);//刷新列表
							top.$.ligerDialog.SQalert({content: result.info,SQ_type: "success"});
							$("#saveBtndiv2").removeClass('Hide');
						}else{
							top.$.ligerDialog.SQalert({content: result.info,SQ_type: "error"});
						}
						//设置巡检数量
						if(routeNum > result.id){
							$("#routeNum").val(result.id);
						}
					}
				});
			});
		}
		
		//初始化列表
		function initGridData(data){
			//设置显示隐藏属性
			$("#ligergrid_detail").addClass('Hide');
			$("#ligergrid_detail2").removeClass('Hide');
			//重新加载列表
			$("#ligergrid_detail2").ligerGrid({
				data: data,
				columns:[
					{ display: '承租人姓名', name: 'cstNm', width: 200, align:'center', enabledSort:true},
					{ display: '支付表号', name: 'paySchNo', width: 160, align:'center', enabledSort:true},
					{ display: '省公司档案袋编号', name: 'portfolioNumber', width: 130, align:'center', enabledSort:true},
					{ display: '总部档案袋编号', name: 'portfolioNumberProvince', width: 130, align:'center', enabledSort:true},
					{ display: '归档状态', name: 'storageStatus', width: 90, align:'center', enabledSort:true,
						render: function (rowdata, rowindex, value, column) {
							var h = '部分归档';
							if(rowdata.storageStatus == '4'){
								h = '全部归档';
							}
							return h;
						}},
					{ display: '巡检状态', name: 'routeState', width: 90, align:'center', enabledSort:true,
						render: function (rowdata, rowindex, value, column) {
							return '未巡检';
						}},
					{ display: '巡检结果', name: 'routeResult', width: 90, align:'center', enabledSort:true,
						render: function (rowdata, rowindex, value, column) {
							return '';
						}},
					{ display:'操作', isSort:false, width: 150, align:'center', 
						render:function (rowdata, rowindex, value){
							var h="";
				            	h+='<a class="sq-button-hasicon" href="javascript:detailPayInfo(';
				                h+="'"+rowdata.id+"'";
				                h+=")\">查看</a>";
							
				                h+='<a class="sq-button-hasicon" href="javascript:updatePayResult(';
				                h+="'"+rowdata.id+"'";
				                h+=")\">更新结果</a>";
				                
							return h;
						}
					}
				],
				//pageSize:10,
				usePager: false,//是否有分页便签
				root:'rows',
				record:'total',
				hideLoadButton:false,
				width:'100%',
				heightDiff:-2,
				checkbox:false,//列表是否有选择框
				rownumbers:true//列表是否有行号
			});
			grid = liger.get("ligergrid_detail2");
		}
		
		//保存巡检列表
		function saveRouteList(){
            var mainId = $("#mainId").val();
            if(null == mainId){
            	top.$.ligerDialog.SQalert({content: "巡检主表ID为空,不能保存巡检明细！",SQ_type: "warning"});
				return false;
            }
            var jsondata = '{mainId:'+mainId+',griddata:'+JSON.stringify(grid.getData())+'}';
            console.log(jsondata);
            $.ligerDialog.confirm('确定保存巡检明细列表吗?', function (flag) {
				if(flag == false)return;
				var wait_dialog = null;
				var url = '<%=path%>/archive/arcRouteDetail/add.do';
				$.ajax({
					type: 'post',
					url: url,
					contentType: 'application/json',
					dataType: 'json',
					data: JSON.stringify(jsondata),
					beforeSend: function(){
						wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
					},
					success:function(msg){
						wait_dialog.close();
						if(msg.success == 1){
							top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "success"});
							//Remove_navTab();//关闭当前页签
							//刷新当前页面
							window.location.href="<%=path%>/archive/arcRouteMain/toDetailPage.do?id="+mainId+"&btnFlag=yes&upFlag=no";
							//执行前置页面的回调函数
							var callback = GET_W2Wcallback ();
							if(callback){
								callback();
							}
						}else{
							top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
						}
					}
				});
			});
        }
		
		//查看支付表巡检详情
		function detailPayInfo(id) {
			var btnFlag = "no";
			var title ="支付表巡检结果详情";
			Add_navTab("arcRoutePayDetail"+id, title, '<%=path%>/archive/arcRouteDetail/toPayDetailPage.do?id='+id+'&btnFlag='+btnFlag , function () {
				grid.reload();
			});
		}
		
		//更新支付表巡检结果
		function updatePayResult(id) {
			var btnFlag = "yes";
			var upFlag = "yes";
			var title ="支付表巡检结果更新";
			var mainId = $("#mainId").val();
			Add_navTab("arcRoutePayUpdate"+id, title, '<%=path%>/archive/arcRouteDetail/toPayDetailPage.do?id='+id+'&btnFlag='+btnFlag , function () {
				//刷新当前页面
				window.location.href="<%=path%>/archive/arcRouteMain/toDetailPage.do?id="+mainId+"&btnFlag="+btnFlag+"&upFlag="+upFlag;
			});
		}
		//导出巡检结果excel
		function importRouteDetail(){
			var mainId = $("#mainId").val();
			var wait_dialog = null;
			$.ajax({
				type: 'get',
				dataType:'json',
				url: '<%=path%>/archive/arcRouteDetail/exportRouteToExcel.do?',
				data:{'mainId':mainId,'eFlag':'tcsq'},
				beforeSend:function(){
					wait_dialog=$.ligerDialog.SQalert({content: '正在导出信息...',SQ_type: "waitting"});
				},
				success:function(msg){
					wait_dialog.close();
					if(msg.success == 1){
						window.open(msg.data);
					}else{
						$.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
					}
				} 
			});
		}
	</script>
</body>
</html>